package com.ruoyi.web.controller.ydz;

import java.util.List;

import com.ruoyi.web.domain.DrugDisease;
import com.ruoyi.web.service.IDrugDiseaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品疾病关联（新）Controller
 * 
 * @author drx
 * @date 2024-03-11
 */
@Controller
@RequestMapping("/ydz/drugDisease")
@Api(tags = "药品疾病关联（新）")
public class DrugDiseaseController extends BaseController
{
    private String prefix = "ydz/drugDisease";

    @Autowired
    private IDrugDiseaseService drugDiseaseService;

    @RequiresPermissions("ydz:drugDisease:view")
    @GetMapping()
    public String drugDisease()
    {
        return prefix + "/drugDisease";
    }

    /**
     * 查询药品疾病关联（新）列表
     */
    @RequiresPermissions("ydz:drugDisease:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("查询药品疾病关联（新）列表")
    public TableDataInfo list(DrugDisease drugDisease)
    {
        startPage();
        List<DrugDisease> list = drugDiseaseService.selectDrugDiseaseList(drugDisease);
        return getDataTable(list);
    }

    /**
     * 导出药品疾病关联（新）列表
     */
    @RequiresPermissions("ydz:drugDisease:export")
    @Log(title = "药品疾病关联（新）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    @ApiOperation("导出药品疾病关联（新）列表")
    public AjaxResult export(DrugDisease drugDisease)
    {
        List<DrugDisease> list = drugDiseaseService.selectDrugDiseaseList(drugDisease);
        ExcelUtil<DrugDisease> util = new ExcelUtil<DrugDisease>(DrugDisease.class);
        return util.exportExcel(list, "药品疾病关联（新）数据");
    }

    /**
     * 新增药品疾病关联（新）
     */
    @GetMapping("/add")
    @ApiOperation("新增药品疾病关联（新）")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存药品疾病关联（新）
     */
    @ApiOperation("新增保存药品疾病关联（新）")
    @RequiresPermissions("ydz:drugDisease:add")
    @Log(title = "药品疾病关联（新）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DrugDisease drugDisease)
    {
        return toAjax(drugDiseaseService.insertDrugDisease(drugDisease));
    }

    /**
     * 修改药品疾病关联（新）
     */
    @ApiOperation("修改药品疾病关联（新）")
    @RequiresPermissions("ydz:drugDisease:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DrugDisease drugDisease = drugDiseaseService.selectDrugDiseaseById(id);
        mmap.put("drugDisease", drugDisease);
        return prefix + "/edit";
    }

    /**
     * 修改保存药品疾病关联（新）
     */
    @ApiOperation("修改保存药品疾病关联（新）")
    @RequiresPermissions("ydz:drugDisease:edit")
    @Log(title = "药品疾病关联（新）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DrugDisease drugDisease)
    {
        return toAjax(drugDiseaseService.updateDrugDisease(drugDisease));
    }

    /**
     * 删除药品疾病关联（新）
     */
    @ApiOperation("删除药品疾病关联（新）")
    @RequiresPermissions("ydz:drugDisease:remove")
    @Log(title = "药品疾病关联（新）", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(drugDiseaseService.deleteDrugDiseaseByIds(ids));
    }
}
